Skip to content

Performance wins across the board#211

Merged
FollowTheProcess merged 7 commits intomainfrom
perf/benchmarks
Apr 23, 2026
Merged

Performance wins across the board#211
FollowTheProcess merged 7 commits intomainfrom
perf/benchmarks

Conversation

@FollowTheProcess
Copy link
Copy Markdown
Owner

@FollowTheProcess FollowTheProcess commented Apr 23, 2026

  • Add some more benchmarks and reset args state between Parse
  • Some quick perf wins
  • Lazily initialise the env var map
  • Eliminate a range loop in favour of utf8.DecodeRuneInString
  • Remove an unneeded slice allocation
  • Simplify some type assertion stuff
  • Reuse the tabwriter to avoid excess allocations

Summary

goos: darwin
goarch: arm64
pkg: go.followtheprocess.codes/cli
cpu: Apple M4 Pro
                     │ before.txt  │              after.txt              │
                     │   sec/op    │   sec/op     vs base                │
ExecuteHelp-14         1.944µ ± 0%   1.693µ ± 0%  -12.93% (p=0.000 n=20)
New-14                 756.7n ± 0%   756.2n ± 0%        ~ (p=0.909 n=20)
Execute-14             219.4n ± 0%   135.2n ± 1%  -38.38% (p=0.000 n=20)
ExecuteSubcommand-14   282.8n ± 0%   147.7n ± 1%  -47.76% (p=0.000 n=20)
Version-14             155.0n ± 0%   138.6n ± 0%  -10.55% (p=0.000 n=20)
geomean                426.7n        323.5n       -24.18%

                     │  before.txt  │               after.txt                │
                     │     B/op     │     B/op      vs base                  │
ExecuteHelp-14         4.433Ki ± 0%   3.705Ki ± 0%  -16.41% (p=0.000 n=20)
New-14                 2.273Ki ± 0%   2.383Ki ± 0%   +4.81% (p=0.000 n=20)
Execute-14               80.00 ± 0%     32.00 ± 0%  -60.00% (p=0.000 n=20)
ExecuteSubcommand-14     320.0 ± 0%     128.0 ± 0%  -60.00% (p=0.000 n=20)
Version-14               272.0 ± 0%     272.0 ± 0%        ~ (p=1.000 n=20) ¹
geomean                  593.4          400.6       -32.50%
¹ all samples are equal

                     │ before.txt  │              after.txt               │
                     │  allocs/op  │ allocs/op   vs base                  │
ExecuteHelp-14          56.00 ± 0%   41.00 ± 0%  -26.79% (p=0.000 n=20)
New-14                  34.00 ± 0%   33.00 ± 0%   -2.94% (p=0.000 n=20)
Execute-14              5.000 ± 0%   2.000 ± 0%  -60.00% (p=0.000 n=20)
ExecuteSubcommand-14   10.000 ± 0%   3.000 ± 0%  -70.00% (p=0.000 n=20)
Version-14              2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=20) ¹
geomean                 11.37        6.952       -38.88%
¹ all samples are equal

pkg: go.followtheprocess.codes/cli/internal/flag
                      │ before.txt  │              after.txt              │
                      │   sec/op    │   sec/op     vs base                │
FlagSet-14              7.881n ± 2%   7.838n ± 1%        ~ (p=0.616 n=20)
Parse-14                136.8n ± 5%   112.1n ± 1%  -18.09% (p=0.000 n=20)
ParseShort-14           71.64n ± 2%   54.17n ± 0%  -24.39% (p=0.000 n=20)
ParseMixed-14           133.6n ± 0%   112.9n ± 0%  -15.49% (p=0.000 n=20)
ParseWithEnv/unset-14   63.25n ± 0%   63.43n ± 0%   +0.28% (p=0.037 n=20)
ParseWithEnv/set-14     130.6n ± 0%   127.1n ± 0%   -2.64% (p=0.000 n=20)
ParseSliceFlag-14       327.6n ± 0%   153.5n ± 0%  -53.15% (p=0.000 n=20)
geomean                 83.34n        67.89n       -18.54%

                      │  before.txt   │              after.txt               │
                      │     B/op      │    B/op     vs base                  │
FlagSet-14               0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=20) ¹
Parse-14                 32.00 ± 0%     16.00 ± 0%  -50.00% (p=0.000 n=20)
ParseShort-14            32.00 ± 0%     16.00 ± 0%  -50.00% (p=0.000 n=20)
ParseMixed-14            32.00 ± 0%     16.00 ± 0%  -50.00% (p=0.000 n=20)
ParseWithEnv/unset-14    0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=20) ¹
ParseWithEnv/set-14      16.00 ± 0%     16.00 ± 0%        ~ (p=1.000 n=20) ¹
ParseSliceFlag-14       224.00 ± 0%     96.00 ± 0%  -57.14% (p=0.000 n=20)
geomean                             ²               -34.17%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                      │  before.txt   │              after.txt               │
                      │   allocs/op   │ allocs/op   vs base                  │
FlagSet-14               0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=20) ¹
Parse-14                 2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.000 n=20)
ParseShort-14            2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.000 n=20)
ParseMixed-14            2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.000 n=20)
ParseWithEnv/unset-14    0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=20) ¹
ParseWithEnv/set-14      1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=20) ¹
ParseSliceFlag-14       12.000 ± 0%     4.000 ± 0%  -66.67% (p=0.000 n=20)
geomean                             ²               -36.49%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

@FollowTheProcess FollowTheProcess added the performance Performance label Apr 23, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 87.57764% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.67%. Comparing base (165d802) to head (2ffceb8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
command.go 72.50% 8 Missing and 3 partials ⚠️
internal/flag/set.go 85.36% 3 Missing and 3 partials ⚠️
internal/style/style.go 0.00% 2 Missing ⚠️
internal/flag/flag.go 98.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #211      +/-   ##
==========================================
+ Coverage   84.96%   85.67%   +0.71%     
==========================================
  Files           9        9              
  Lines        2088     1592     -496     
==========================================
- Hits         1774     1364     -410     
+ Misses        245      172      -73     
+ Partials       69       56      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FollowTheProcess FollowTheProcess merged commit 3190775 into main Apr 23, 2026
11 checks passed
@FollowTheProcess FollowTheProcess deleted the perf/benchmarks branch April 23, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant